/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SLE_ANNOUNCE_CONFIG_H
#define SLE_ANNOUNCE_CONFIG_H

#include <stdint.h>
#include "sle_device_config.h"

#define SLE_ANNOUNCE_DATA_ANN_MAX_LENGTH 200
#define SLE_ANNOUNCE_DATA_MAX_RSP_LENGTH 200
#define SLE_ANNOUNCE_COUNT_NUM 16

typedef struct {
    uint16_t announceLength;
    uint8_t *announceData;
    uint16_t responceLength;
    uint8_t *responceData;
} SleAnnounceData;

typedef enum {
    SLE_ANNOUNCE_NONCONN_NONSCAN_MODE      = 0x00,
    SLE_ANNOUNCE_CONNECTABLE_NONSCAN_MODE  = 0x01,
    SLE_ANNOUNCE_NONCONN_SCANABLE_MODE     = 0x02,
    SLE_ANNOUNCE_CONNECTABLE_SCANABLE_MODE = 0x03,

    SLE_ANNOUNCE_CONNECTABLE_DIRECTED_MODE = 0x07,
} SleAnnounceMode_t;
typedef uint8_t SleAnnounceMode;

typedef enum {
    SLE_ANNOUNCE_T_ROAL_CAN_NEGO = 0,
    SLE_ANNOUNCE_G_ROAL_CAN_NEGO,
    SLE_ANNOUNCE_T_ROAL_NO_NEGO,
    SLE_ANNOUNCE_G_ROAL_NO_NEGO
} SleAnnounceRole_t;
typedef uint8_t SleAnnounceRole;

typedef enum {
    SLE_ANNOUNCE_NONE_LEVEL,
    SLE_ANNOUNCE_NORMAL_LEVEL,
    SLE_ANNOUNCE_PRIORITY_LEVEL,
    SLE_ANNOUNCE_PAIRED_LEVEL,
    SLE_ANNOUNCE_SPECIAL_LEVEL,
} SleAnnounceLevel_t;
typedef uint8_t SleAnnounceLevel;

typedef enum {
    SLE_ANNOUNCE_76_CHANEL = 1,
    SLE_ANNOUNCE_77_CHANEL = 2,
    SLE_ANNOUNCE_78_CHANEL = 4,
    SLE_ANNOUNCE_DEFAULT_ALL_CHANEL = 7,
} SleAnnounceChanel_t;
typedef uint8_t SleAnnounceChanel;

#ifndef DEFAULT_SLE_ANNOUNCE_PARAM
#define DEFAULT_SLE_ANNOUNCE_PARAM

#define DEFAULT_SLE_ADV_MODE SLE_ANNOUNCE_CONNECTABLE_SCANABLE_MODE
#define DEFAULT_SLE_ADV_ROLE SLE_ANNOUNCE_T_ROAL_CAN_NEGO
#define DEFAULT_SLE_ADV_LEVEL SLE_ANNOUNCE_NORMAL_LEVEL
#define DEFAULT_SLE_ADV_INTERVAL_MIN 0xc8
#define DEFAULT_SLE_ADV_INTERVAL_MAX 0xc8
#define DEFAULT_SLE_ADV_CHANNEL_MAP SLE_ANNOUNCE_DEFAULT_ALL_CHANEL
#define DEFAULT_SLE_ADV_TX_POWER 20
#define DEFAULT_SLE_ADV_CONN_INTV_MIN 0x64
#define DEFAULT_SLE_ADV_CONN_INTV_MAX 0x64
#define DEFAULT_SLE_ADV_CONN_AX_LATENCY 0x1F3
#define DEFAULT_SLE_ADV_CONN_SUPERVISION_TIMEOUT 0x1F4

#endif //DEFAULT_SLE_ANNOUNCE_PARAM

typedef struct {
    uint8_t handle;
    SleAnnounceMode mode;
    SleAnnounceRole role;
    SleAnnounceLevel level;
    uint32_t annonceIntervalMin;    //  [0x000020,0xffffff], 单位125us
    uint32_t annonceIntervalMax;    //  [0x000020,0xffffff], 单位125us
    SleAnnounceChanel channelMap;
    int8_t txPower;                 //  [-127, 20], 0x7F：不设置特定发送功率
    SleDeviceAddress ownAddr;       //  框架内部使用,外部配置无效
    SleDeviceAddress peerAddr;      //  reserved for level:SLE_ANNOUNCE_SPECIAL_LEVEL
    uint16_t connectIntervalMin;    //  [0x001E,0x3E80], role == SLE_ANNOUNCE_T_ROAL_NO_NEGO时无需配置
    uint16_t connectIntervalMax;    //  [0x001E,0x3E80], role == SLE_ANNOUNCE_T_ROAL_NO_NEGO时无需配置
    uint16_t connectLatency;        //  [0x0000,0x01F3], role == SLE_ANNOUNCE_T_ROAL_NO_NEGO时无需配置
    uint16_t connectTimeout;        //  [0x000A,0x0C80], role == SLE_ANNOUNCE_T_ROAL_NO_NEGO时无需配置
    void *extParam;                 //  reserved
} SleAnnounceParam;

typedef enum {
    SLE_ANNOUNCE_ENABLED_STATE = 0,
    SLE_ANNOUNCE_ENABLING_STATE = 1,
    SLE_ANNOUNCE_DISABLING_STATE = 2,
    SLE_ANNOUNCE_DISABLED_STATE = 3,
    /** keep SLE_ANNOUNCE_ERROR_STATE at the end of hostStatus */
    SLE_ANNOUNCE_ERROR_STATE = 0xFF,
} SleAnnounceState_t;
typedef uint8_t SleAnnounceState;

#ifndef SleAnnounceStateStr
#define SleAnnounceStateStr(state)                          \
    (state == SLE_ANNOUNCE_ENABLED_STATE) ? "ENABLED" :     \
    (state == SLE_ANNOUNCE_ENABLING_STATE) ? "ENABLING" :   \
    (state == SLE_ANNOUNCE_DISABLING_STATE) ? "DISABLING" : \
    (state == SLE_ANNOUNCE_DISABLED_STATE) ? "DISABLED" :   \
    (state == SLE_ANNOUNCE_ERROR_STATE) ? "ERROR" : "UNKNOWN"
#endif

#define SLE_MAX_ANNOUNCE_ID_NUM 16  //SDK 中软件限制最大为16，实际3863支持3路广播
#define SLE_DEFAULT_ANNOUNCE_ID 1

#endif // SLE_ANNOUNCE_CONFIG_H